<?php

// 应用常用函数
function write_log($content, $preFileName = null, $path = null, $rootPath = '')
{
    $preFileName = $preFileName ? $preFileName . '_' . date('Ymd', time()) : 'log_' . date('Ymd', time());

    $path = $path ? $path : 'temp';

    $path = $rootPath . "logs/$path/" . date('Ym', time()) . '/';

    if (!is_dir($path)) {
        mkdir($path, 0755, true);
    }

    $ext = '.log';

    $filePath = $path . $preFileName . $ext;

    $content = var_export($content, true);

    $tmp = "\n\n================= " . date('Y-m-d H:i:s') . " ===================\n\n";

    $content = $tmp . $content;

    return file_put_contents($filePath, $content, FILE_APPEND);
}

function testWrite()
{
    echo "hello write";
}